<?php
require_once '../sub/init.php';
header("Cache-control: private");
require_once 'chkUadm.php';
require_once ZEAI.'cache/config_crm.php';
require_once ZEAI.'cache/udata.php';
$t = (ifint($t,'1-2','1'))?$t:1;
$SQL = " (flag=1 OR flag=-2) AND kind<>4 AND admid>0 AND crm_ugrade=0 ";
//非超管门店+地区 
$SQL .= getAgentSQL();

//超管搜索按门店
if (ifint($agentid) && CRM_ADM)$SQL .= " AND agentid=$agentid";

//按会员搜索
$Skey = trimhtml($Skey);
if (!empty($Skey)){
	if(ifmob($Skey)){
		$SQL .= " AND (mob=".$Skey." OR mob2=".$Skey.")";	
	}elseif(ifint($Skey)){
		$SQL .= " AND id=".$Skey;	
	}else{
		$SQL .= " AND (( truename LIKE '%".$Skey."%' ) OR ( crm_ubz LIKE '%".$Skey."%' ) OR ( uname LIKE '%".$Skey."%' ) OR ( nickname LIKE '%".$Skey."%' ) OR ( nickname LIKE '%".urlencode($Skey)."%' )) ";
	}
}

//按红娘
$Skey2 = trimhtml($Skey2);
if (!empty($Skey2)){
	if(ifint($Skey2)){
		$SQL .= " AND (admid=".$Skey2." OR hnid=".$Skey2.") ";// OR hnid2=".$Skey2."
	}else{
		$SQL .= " AND (    admname LIKE '%".$Skey2."%' OR hnname LIKE '%".$Skey2."%' ) ";// OR hnname2 LIKE '%".$Skey2."%' 
	}
}

//按客户分类
if(ifint($crm_ukind))$SQL  .= " AND crm_ukind=$crm_ukind";
if (ifint($ifcontact))$SQL .= " AND (mob<>'' OR mob2<>'' OR weixin<>'') ";
if (ifint($myinfobfb))$SQL .= " AND myinfobfb>$myinfobfb ";
if ($photo_s == 1)$SQL     .= " AND photo_s<>'' ";

//超管搜索按门店
if (ifint($agentid) && CRM_ADM){
	$SQL_AGENT .= " AND agentid=$agentid ";	
}else{
	$SQL_AGENT .=" AND agentid=$session_agentid ";
}
if($ifhnid == 'ifhnid0'){
	$SQL .= " AND hnid=0 ";
}elseif($ifhnid == 'ifhnid1'){
	$SQL .= " AND hnid>0 ";
}
if (ifint($sex))$SQL .= " AND sex=$sex ";
if (ifint($crm_fromclue))$SQL .= " AND crm_fromclue=$crm_fromclue ";

if($ifmy==1)$SQL .= " AND (admid=".$session_uid." OR hnid=".$session_uid.") ";
if($index_hntime==1)$SQL .= " AND hnid=".$session_uid;

//坠海
if($ifsea==1 && $_CRM['sea_hn_day']>0 && $_CRM['sea_hn_day_tip']>0){
	$seatime1 = ($_CRM['sea_hn_day']-$_CRM['sea_hn_day_tip'])*86400;
	$seatime2 = $_CRM['sea_hn_day']*86400;
	$SQL .= " AND (".ADDTIME." - seatime) > $seatime1 AND (".ADDTIME." - seatime) < $seatime2 ";
}
switch ($sort) {
	case 'regtime0':$sortSQL = " ORDER BY regtime ";break;
	case 'regtime1':$sortSQL = " ORDER BY regtime DESC ";break;
	case 'endtime0':$sortSQL = " ORDER BY endtime ";break;
	case 'endtime1':$sortSQL = " ORDER BY endtime DESC ";break;
	case 'admtime0':$sortSQL = " ORDER BY admtime,id DESC";break;
	case 'admtime1':$sortSQL = " ORDER BY admtime DESC,id DESC";break;
	case 'bbsnum0':$sortSQL = " ORDER BY bbsnum,id DESC";break;
	case 'bbsnum1':$sortSQL = " ORDER BY bbsnum DESC,id DESC ";break;
	case 'hntime0':$sortSQL = " ORDER BY hntime,id DESC";break;
	case 'hntime1':$sortSQL = " ORDER BY hntime DESC,id DESC";break;
	case 'bbs_nexttime0':$sortSQL = " ORDER BY bbs_nexttime,id DESC ";break;
	case 'bbs_nexttime1':$sortSQL = " ORDER BY bbs_nexttime DESC,id DESC ";break;
	case 'bbs_endtime0':$sortSQL = " ORDER BY bbs_endtime,id DESC";break;
	case 'bbs_endtime1':$sortSQL = " ORDER BY bbs_endtime DESC,id DESC";break;
	default:$sortSQL = " ORDER BY hntime DESC,id DESC ";break;
}
$BBS_numSQL       = ",(SELECT COUNT(*) FROM ".__TBL_CRM_BBS__." WHERE uid=U.id".$SQLBBSss.") AS bbsnum ";
$BBS_nexttimeSQL  = ",(SELECT nexttime FROM ".__TBL_CRM_BBS__." WHERE uid=U.id".$SQLBBSss." ORDER BY nexttime DESC LIMIT 1) AS bbs_nexttime";
$BBS_endtimeSQL   = ",(SELECT addtime FROM ".__TBL_CRM_BBS__."  WHERE uid=U.id".$SQLBBSss." ORDER BY addtime DESC LIMIT 1 ) AS bbs_endtime";
//客户跟进：
if(!empty($bbskind) && $bbskind!='gj_no'){
	$today = YmdHis(ADDTIME,'Ymd');
	switch ($bbskind) {
		case 'gj_month_no':$SQLBBS= " AND (".ADDTIME." - addtime) > 604800 ";break;//一周未跟进
		case 'gj_yes':$SQLBBS= "  ";break;//有跟进
		case 'gj_today_no':$SQLBBS= " AND ( TO_DAYS(from_unixtime(nexttime))-TO_DAYS(NOW()) = 0 ) AND nexttime>0 ";break;//今天需跟进
		case 'gj_tomorrow_no':$SQLBBS= " AND (TO_DAYS(from_unixtime(nexttime))-TO_DAYS(NOW())) = 1 ";break;//明天需跟进、、date_format(now(),'%Y-%m-%d')
		case 'gj_today_yes':$SQLBBS= " AND ( date_format(from_unixtime(addtime),'%Y-%m-%d') = '$today' ) ";break;//今天已跟进
	}
	$uidlist = array();
	$rtU=$db->query("SELECT uid FROM ".__TBL_CRM_BBS__." A,(SELECT MAX(id) AS max_id FROM ".__TBL_CRM_BBS__." GROUP BY uid) B WHERE A.id=B.max_id ".$SQLBBS." ORDER BY A.id DESC");// GROUP BY uid
	$totalU = $db->num_rows($rtU);
	if ($totalU > 0) {
		for($iU=1;$iU<=$totalU;$iU++) {
			$rowsU = $db->fetch_array($rtU,'name');
			if(!$rowsU)break;
			$uidlist[]=$rowsU['uid'];
		}
		$uidlist = (is_array($uidlist))?implode(',',$uidlist):'';
		$SQL_BBS_inU=" AND id in ($uidlist)";
	}else{
		$SQL_BBS_inU=" AND 1=2 ";
	}
}else{
	$SQL_BBS_inU = "";
}
if($bbskind=='gj_no')$SQL .= " AND ((SELECT COUNT(*) FROM ".__TBL_CRM_BBS__." WHERE uid=U.id)=0) ";//未跟进
$fld = "id,crm_ukind,crm_ukind,agentid,agenttitle,admid,admname,admtime,hnid,hnname,hnid2,hnname2,uname,truename,nickname,photo_s,sex,grade,birthday,edu,heigh,areatitle,area2title,love,regtime,endtime,kind,flag,tguid,crm_ubz,seatime";
$rt = $db->query("SELECT ".$fld.$BBS_numSQL.$BBS_nexttimeSQL.$BBS_endtimeSQL." FROM ".__TBL_USER__." U WHERE ".$SQL.$SQL_BBS_inU.$sortSQL." LIMIT ".$_ADM['admLimit']);
$total = $db->num_rows($rt);
$searchA  = "crm_sq.php?sex=$sex&photo_s=$photo_s&ifsea=$ifsea&ifmy=$ifmy&myinfobfb=$myinfobfb&ifcontact=$ifcontact&myinfobfb=$myinfobfb&agentid=$agentid&t=$t&Skey=$Skey&Skey2=$Skey2";
$sorthref = $searchA."&ifhnid=$ifhnid&bbskind=$bbskind&crm_ukind=$crm_ukind&sort=";?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/cache/udata.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo HOST;?>/res/select4.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
<link href="css/crm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<style>
.gradeflag{display:block;color:#999;padding-top:5px;padding-bottom:10px;font-family:'Arial'}
.sortbox{display:inline-block;width:100px}
.box{padding-top:10px;padding-bottom:20px;min-width:1300px}
</style>
<body>
<div class="box">
    <div class="topsearch">
    	<dl>
        <dt style="margin-top:1px">客户筛选</dt>
        <dd>
        <form name="form1" method="get" action="<?php echo SELF; ?>">
          <!--超管按门店查询-->
          <?php if(CRM_ADM){?>
          <?php
            $rt2=$db->query("SELECT id,title FROM ".__TBL_CRM_AGENT__." WHERE flag=1 ORDER BY px DESC,id DESC");
            $total2 = $db->num_rows($rt2);
            if ($total2 > 0) {?>
                <select name="agentid" class="size2 picmiddle">
                <option value="">不限门店</option>
				<?php
                for($j=0;$j<$total2;$j++) {
                    $rows2 = $db->fetch_array($rt2,'num');
                    if(!$rows2) break;
                    $clss=($agentid==$rows2[0])?' selected':'';?><option value="<?php echo $rows2[0];?>"<?php echo $clss;?>><?php echo dataIO($rows2[1],'out');?></option><?php
                }?>
                </select>　<?php
            }}?>
          <!---->
        <input name="Skey" type="text" id="Skey" maxlength="25" class="W200 input size2" placeholder="按客户UID/姓名/昵称/手机/备注" value="<?php echo $Skey; ?>">　
        <input name="Skey2" type="text" id="Skey2" size="30" maxlength="25" class="W100 input size2" placeholder="按红娘ID/姓名" value="<?php echo $Skey2; ?>">　
        <script>nulltext='性别';zeai_cn__CreateFormItem('select','sex','<?php echo $sex; ?>','class="size2 SW_edu picmiddle"',sex_ARR);</script>　
        <script>nulltext='资料完善度';zeai_cn__CreateFormItem('select','myinfobfb','<?php echo $myinfobfb; ?>','class=" size2 picmiddle"',[{i:"10",v:"完善度>10%"},{i:"60",v:"完善度>60%"}]);</script>　
		<script>nulltext='线索来源';zeai_cn__CreateFormItem('select','crm_fromclue','<?php echo $crm_fromclue; ?>','class="size2 picmiddle"',crm_fromclue_ARR);</script>
        <div class="br"></div>
        <input type="checkbox" name="ifcontact" id="ifcontact" class="checkskin" value="1"<?php echo ($ifcontact == 1)?' checked':''; ?> ><label for="ifcontact" class="checkskin-label"><i></i><b class="W75 S14">有联系方法</b></label>
		<input type="checkbox" name="photo_s" id="photo_s" class="checkskin" value="1"<?php echo ($photo_s == 1)?' checked':''; ?>><label for="photo_s" class="checkskin-label"><i></i><b class=" S14">有头像</b></label>
        <input type="checkbox" name="ifmy" id="ifmy" class="checkskin" value="1"<?php echo ($ifmy == 1)?' checked':''; ?>><label for="ifmy" class="checkskin-label"><i></i><b class="W60 S14">我的客户</b></label>
		<?php if($_CRM['sea_hn_day']>0 && $_CRM['sea_hn_day_tip']>0){?><input type="checkbox" name="ifsea" id="ifsea" class="checkskin" value="1"<?php echo ($ifsea == 1)?' checked':''; ?>><label for="ifsea" class="checkskin-label"><i></i><b class="W60 S14">即将坠海</b></label><?php }?>
        
        <button type="submit" class="btn size2 QING"><i class="ico">&#xe6c4;</i> 搜索</button>
        <input name="submitok" type="hidden" value="<?php echo $submitok; ?>" />
        <input type="hidden" name="p" value="<?php echo $p;?>" />
        <input type="hidden" name="t" value="<?php echo $t;?>" />
        <input type="hidden" name="k" value="<?php echo $k;?>" />
        <input type="hidden" name="crm_ukind" value="<?php echo $crm_ukind;?>" />
        </form>
        </dd>
        </dl>
	</div>
    <div class="topsearch">
		<dl>
       	  <dt>客户分类</dt>
          <dd>
            <a href="javascript:;" <?php echo (empty($crm_ukind))?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&crm_ukind=&bbskind=<?php echo $bbskind;?>&ifhnid=<?php echo $ifhnid;?>')">不限</a>
            <?php
			$crm_ukindARR = json_decode($_UDATA['crm_ukind'],true);
			if (count($crm_ukindARR) >= 1 && is_array($crm_ukindARR)){
				foreach ($crm_ukindARR as $V){
					$ukind_id    = $V['i'];
					$ukind_title = $V['v'];
					$ukindcls = ($ukind_id==$crm_ukind)?' class="ed"':'';?>
					<a href="javascript:;" <?php echo $ukindcls;?> onClick="zeai.openurl('<?php echo $searchA;?>&crm_ukind=<?php echo $ukind_id;?>&bbskind=<?php echo $bbskind;?>&ifhnid=<?php echo $ifhnid;?>')"><?php echo $ukind_title;?></a>
					<?php
				}
			}?>
          </dd>
        </dl>
		<dl>
        	<dt>客户跟进</dt>
            <dd>
            <a href="javascript:;" <?php echo (empty($bbskind))?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')">不限</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_yes')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_yes&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="有跟进记录">有跟进</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_no')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_no&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="没有跟进记录">未跟进</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_month_no')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_month_no&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="超过一周没有跟进记录">一周未跟进</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_today_no')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_today_no&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="今天需跟进(根据下次联系时间匹配)">今天需跟进</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_tomorrow_no')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_tomorrow_no&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="明天需跟进(根据下次联系时间匹配)">明天需跟进</a>
            <a href="javascript:;" <?php echo ($bbskind=='gj_today_yes')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&bbskind=gj_today_yes&crm_ukind=<?php echo $crm_ukind;?>&ifhnid=<?php echo $ifhnid;?>')" title="今天新增的跟进记录">今天已跟进</a>
            </dd>
        </dl>
		<dl>
        	<dt>售前红娘</dt>
          <dd>
            <a href="javascript:;" <?php echo (empty($ifhnid))?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&ifhnid=&bbskind=<?php echo $bbskind;?>&crm_ukind=<?php echo $crm_ukind;?>')">不限</a>
            <a href="javascript:;" <?php echo ($ifhnid=='ifhnid0')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&ifhnid=ifhnid0&bbskind=<?php echo $bbskind;?>&crm_ukind=<?php echo $crm_ukind;?>')" title="未分配售前红娘">未分配</a>
            <a href="javascript:;" <?php echo ($ifhnid=='ifhnid1')?' class="ed"':''?> onClick="zeai.openurl('<?php echo $searchA;?>&ifhnid=ifhnid1&bbskind=<?php echo $bbskind;?>&crm_ukind=<?php echo $crm_ukind;?>')" title="已分配售前红娘">已分配</a>
          </dd>
        </dl>
		<dl>
       	  <dt style="margin-top:0">升降排序</dt>
            <dd>
                <div class="sortbox">      
                    注册时间<div class="sortSPAN ">
                    <em title="升序" onclick="zeai.openurl('<?php echo $sorthref."regtime0";?>')" <?php echo($sort == 'regtime0')?' class="ed"':''; ?>></em>
                    <em title="降序" onclick="zeai.openurl('<?php echo $sorthref."regtime1";?>')" <?php echo($sort == 'regtime1')?' class="ed"':''; ?>></em>
                    </div>
                </div>
                <div class="sortbox">     
                    登录时间<div class="sortSPAN ">
                    <em title="升序" onclick="zeai.openurl('<?php echo $sorthref."endtime0";?>')" <?php echo($sort == 'endtime0')?' class="ed"':''; ?>></em>
                    <em title="降序" onclick="zeai.openurl('<?php echo $sorthref."endtime1";?>')" <?php echo($sort == 'endtime1')?' class="ed"':''; ?>></em>
                    </div>
                </div>
                <div class="sortbox">    
                    认领时间<div class="sortSPAN ">
                    <em title="升序" onclick="zeai.openurl('<?php echo $sorthref."admtime0";?>')" <?php echo($sort == 'admtime0')?' class="ed"':''; ?>></em>
                    <em title="降序" onclick="zeai.openurl('<?php echo $sorthref."admtime1";?>')" <?php echo($sort == 'admtime1')?' class="ed"':''; ?>></em>
                    </div>
                </div>
                <div class="sortbox" title="按售前分配时间排序">  
                    售前分配<div class="sortSPAN ">
                    <em title="升序" onclick="zeai.openurl('<?php echo $sorthref."hntime0";?>')" <?php echo($sort == 'hntime0')?' class="ed"':''; ?>></em>
                    <em title="降序" onclick="zeai.openurl('<?php echo $sorthref."hntime1";?>')" <?php echo($sort == 'hntime1')?' class="ed"':''; ?>></em>
                    </div>
                </div>
                <a class="refresh btn size2 BAI FR" onClick="location.reload(true);"><i class="ico">&#xe67d;</i> 刷新本页面</a>
            </dd>
        </dl>
	</div>
	<?php
    if ($total <= 0 ) {
        echo "<div class='nodataico'><i></i>暂无信息<br><a class='aQINGed' href='javascript:history.back(-1)'>返回</a></div>";
    } else {
        $page_skin=2;$pagemode=3;$pagesize=$_ADM['admPageSize'];require_once ZEAI.'sub/page.php';?>
        <form id="zeaiFORM" method="get" action="<?php echo SELF; ?>">
    	<table class="tablelist">
        <tr>
        <th width="30"><input type="checkbox" id="checkboxall1" class="checkskin checkboxall"><label for="checkboxall1" class="checkskin-label"><i class="i1"></i></label></th>
        <th width="110">头像/UID/昵称</th>
        <th width="5" align="center">&nbsp;</th>
        <th width="130" align="left">基本资料</th>
        <th width="80" align="left">工作地区</th>
        <th width="80">户籍地区</th>
        <th width="160" align="left">所属门店/服务红娘</th>
        <th width="120" align="center">最后联系
                <div class="sort ">
                <a title="升序" href="<?php echo $sorthref."bbs_endtime0";?>" <?php echo($sort == 'bbs_endtime0')?' class="ed"':''; ?>></a>
                <a title="降序" href="<?php echo $sorthref."bbs_endtime1";?>" <?php echo($sort == 'bbs_endtime1')?' class="ed"':''; ?>></a>
                </div>
        </th>
        <th width="120" align="center">下次联系
                <div class="sort">
                <a title="升序" href="<?php echo $sorthref."bbs_nexttime0";?>" <?php echo($sort == 'bbs_nexttime0')?' class="ed"':''; ?>></a>
                <a title="降序" href="<?php echo $sorthref."bbs_nexttime1";?>" <?php echo($sort == 'bbs_nexttime1')?' class="ed"':''; ?>></a>
                </div>
        </th>
        <th width="10" align="center">
        </th>
        <th align="center">客户分类/备注</th>
        <th width="111" align="center" style="min-width:100px">跟进(次)<div class="sort">
                <a title="升序" href="<?php echo $sorthref."bbsnum0";?>" <?php echo($sort == 'bbsnum0')?' class="ed"':''; ?>></a>
                <a title="降序" href="<?php echo $sorthref."bbsnum1";?>" <?php echo($sort == 'bbsnum1')?' class="ed"':''; ?>></a>
          </div></th>
        <th width="140">帐号信息</th>
        <th width="15">&nbsp;</th>
        </tr>
        <?php
        for($i=1;$i<=$pagesize;$i++) {
            $rows = $db->fetch_array($rt,'name');
            if(!$rows) break;
            //
            $agentid = $rows['agentid'];
            $agenttitle = dataIO($rows['agenttitle'],'out');
            $agenttitle = (!empty($agenttitle))?'<font class="C999">门店：</font>'.$agenttitle.'<br>':'';
            $admid   = $rows['admid'];
            $admname = dataIO($rows['admname'],'out');
            $admtime = intval($rows['admtime']);
            $hnid    = $rows['hnid'];
            $hnname  = dataIO($rows['hnname'],'out');
            $hnid2   = $rows['hnid2'];
            $hnname2 = dataIO($rows['hnname2'],'out');
            $crm_ukind = intval($rows['crm_ukind']);
            $seatime = intval($rows['seatime']);
            //
            $id = $rows['id'];$uid = $id;
            $sex      = $rows['sex'];
            $grade    = $rows['grade'];
            $photo_s  = $rows['photo_s'];
            
            $truename = strip_tags($rows['truename']);
            $uname = str_replace($Skey,"<font color=red><b>".$Skey."</b></font>",$uname);
            $truename = str_replace($Skey,"<font color=red><b>".$Skey."</b></font>",$truename);
            $nickname = dataIO($rows['nickname'],'out');
            $nickname = str_replace($Skey,"<font color=red><b>".$Skey."</b></font>",$nickname);
            //
            $areatitle = dataIO($rows['areatitle'],'out');
            $area2title = dataIO($rows['area2title'],'out');
            $crm_ubz = dataIO($rows['crm_ubz'],'out');
            //
            $tguid      = $rows['tguid'];
            $birthday  = $rows['birthday'];
            $age   = (@getage($birthday)<=0)?'':@getage($birthday).'岁';
            $edu   = udata('edu',intval($rows['edu']));
            $love  = udata('love',intval($rows['love']));
            $heigh = udata('heigh',intval($rows['heigh']));
            if(!empty($nickname)){
                $title = $nickname;
            }else{
                if(!empty($truename)){
                    $title=$truename;	
                }else{
                    $title = 'UID:'.$uid;
                }
            }
            $photo_s_url = (!empty($photo_s))?$_ZEAI['up2'].'/'.$photo_s:HOST.'/res/photo_s'.$sex.'.png';
            if(empty($rows['nickname'])){if(empty($rows['truename'])){$title = $rows['mob'];}else{$title = $rows['truename'];}}else{
                $title = $nickname;
            }
            $bbsnum = intval($rows['bbsnum']);
            $bbsnumCls=($bbsnum>0)?'aLAN gjlist':'aHUI gjlist';
            $bbs_endtime = intval($rows['bbs_endtime']);
            $bbs_nexttime = intval($rows['bbs_nexttime']);
            $title2 = (!empty($nickname))?urlencode(trimhtml($nickname).'/'.$uid):$uid;
        ?>
        <tr id="tr<?php echo $id;?>">
          <td width="30"><input type="checkbox" name="list[]" value="<?php echo $id; ?>" id="uid<?php echo $id; ?>" class="checkskin"><label for="uid<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label>　
            </td>
          <td width="110" class="padding10">
            <a href="javascript:;" uid="<?php echo $uid;?>" title2="<?php echo $title2;?>" photo_s_url="<?php echo $photo_s_url;?>" class="photo_ss"><img src="<?php echo $photo_s_url; ?>" class="photo_s"></a>
            <a href="javascript:;" uid="<?php echo $uid;?>" title2="<?php echo $title2;?>" photo_s_url="<?php echo $photo_s_url;?>" class="photo_ss"><?php echo uicon($sex.$grade);?><?php echo $uid;?></a>
            <?php if(!empty($rows['nickname']))echo "</br><font class='uleft'>".$nickname."</font>";?>
            </td>
          <td width="5" align="center">
                  
          </td>
          <td width="130" align="left"  class="lineH200">
          
            <?php if (!empty($truename)){?><font class="C999">姓名：</font><?php echo $truename;?><br><?php }?>
            <font class="C999">年龄：</font><?php echo $age.'('.substr($birthday,0,4).')';?><br>
            <?php if (!empty($love)){?><font class="C999">婚况：</font><?php echo $love;?><br><?php }?>
            <?php if (!empty($edu)){?><font class="C999">学历：</font><?php echo $edu;?><br><?php }?>
            <?php if (!empty($heigh)){?><font class="C999">身高：</font><?php echo $heigh;?><?php }?>
          
          </td>
          <td width="80" align="left" class="lineH200" style="padding:10px 0"><?php echo str_replace(" ","<br>",$areatitle); ?></td>
          <td width="80" class="lineH200"><?php echo str_replace(" ","<br>",$area2title); ?></td>
          <td width="160" align="left" class="lineH200">
            <?php echo $agenttitle;?>
            <?php $adm_str = ($admtime>0)?'认领':'录入';?>
            <?php if(!empty($admid)){echo '<font class="C999">'.$adm_str.'：</font>'.$admname.' <font class="C999">ID:'.$admid.'</font>';}?>
    
            <br><font class="C999 textmiddle">售前：</font><?php
            if(empty($hnid)){
                if(in_array('crm_hn_utask_sq_add',$QXARR)){?><a href="javascript:;" photo_s_url="<?php echo $photo_s_url;?>" class="btn size1 QING_ hnadd" uid="<?php echo $id;?>" title2="<?php echo $title2;?>">分配售前</a><br><?php }
            }else{?><span class="textmiddle"><?php echo $hnname;?> <font class="C999">ID:<?php echo $hnid;?></font></span>
                <?php if(in_array('crm_hn_utask_sq_mod',$QXARR)){?><a href="javascript:;" photo_s_url="<?php echo $photo_s_url;?>" class="btn size1 QING_ hnmod" uid="<?php echo $id;?>" title2="<?php echo $title2;?>">更换</a><?php }
				 $seatime_str=sea_djs($seatime,'sq');echo (!empty($seatime_str))?'<div class="center">'.$seatime_str.'</center>':'';
            }?> 
    
          </td>
          <td width="120" align="center" class="lineH150">
            <?php
            if ($bbs_endtime > 0){echo '<div>'.YmdHis($bbs_endtime,'YmdHi').'</div>';
                $bbsday = intval(ADDTIME-$bbs_endtime);
                $bbsday = intval($bbsday/86400);
                if($bbsday>0){
                    $bbsday_cls = ($bbsday>7)?' class="Cf00"':'';
                    echo '<div'.$bbsday_cls.'>已过'.$bbsday.'天未联系</div>';
                }
            }?>
          </td>
          <td width="120" align="center" class="lineH150">
            <?php
            if ($bbs_nexttime > 0){
                echo '<div>'.YmdHis($bbs_nexttime,'YmdHi').'</div>';
                $nextday = intval($bbs_nexttime-ADDTIME);
                $nextday = intval($nextday/86400);
                if($bbs_nexttime<ADDTIME){//过期
                    $nextday_str = ($nextday<-1)?abs($nextday).'天':'';
                    echo '<div class="Cf00">过期'.$nextday_str.'未跟进</div>'; 
                }else{
                    if($nextday>=1){
                        echo '<div class="C090">'.$nextday.'天后联系</div>'; 
                    }
                }
            }?>
          </td>
          <td width="10" align="center" >
    
          </td>
          <td align="center" ><br><br><a class="aBAI"  onClick="zeai.iframe('修改【<?php echo $id;?>】客户分类','crm_user.php?submitok=usre_crm_ukind_mod&uid=<?php echo $id;?>',700,320)"><?php echo udata('crm_ukind',$crm_ukind); ?></a><br><br>
          <?php if(CRMQX('crm_user_bz') ||  CRMQX('crm_user_bz_my') && ifmyu($uid)){?>
          <a href="#" onClick="zeai.iframe('给【<?php echo $id;?>】备注','crm_user.php?submitok=bz&uid=<?php echo $id;?>',500,280)" class="editico tips" tips-title='<?php echo $crm_ubz;?>'></a><?php }?><span id="bz<?php echo $id;?>"><?php if (!empty($crm_ubz))echo $crm_ubz;?></span>
          
          </td>
          <td width="111" align="center">
            <a href="javascript:;" class="btn size2 tips gjlist btn_numtips" tips-title='点击查看跟进' photo_s_url=<?php echo $photo_s_url;?> tips-direction='top' uid="<?php echo $id;?>" title2="<?php echo $title2;?>"><i class="ico">&#xe622;</i> 跟进<?php echo ($bbsnum>0)?'<span>'.$bbsnum.'</span>':'';?></a>
          </td>
          <td width="140" class="lineH200">
            <font class="C999">注册时间：</font><?php echo YmdHis($rows['regtime'],'Ymd');?><br>
            <font class="C999">最后登录：</font><?php echo YmdHis($rows['endtime'],'Ymd');?></font><br>
            <font class="C999">帐号类型：</font><?php echo user_kind($rows['kind']); ?></font><br>
            <font class="C999">帐号状态：</font><?php echo flagtitle($rows['flag']);?></font>
          </td>
          <td width="15" class="lineH200">&nbsp;</td>
          </tr>
        <?php } ?>
    </table>
  </form>
    <?php }?>
    <div class="clear"></div>
</div>
<?php if ($total > 0 ) {?>
<div class="listbottombox">
    <input type="checkbox" id="checkboxall2" class="checkskin checkboxall"><label for="checkboxall2" class="checkskin-label"><i class="i1"></i></label>　
    <button type="button" value="" class="btn size2 QING disabled action" onClick="hnTask(this,1,'批量分配售前红娘');">分配售前红娘</button>　
    <button type="button" value="" class="btn size2 QING2 disabled action" onClick="hnTask(this,2,'批量更换售前红娘');">更换售前红娘</button>　
    <?php if ($total > 0)echo '<div class="pagebox FR">'.$pagelist.'</div>'; ?></div>
</div>
<script>var bg = '<?php echo $_Style['list_bg']; ?>',overbg   = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';</script>
<script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script>
zeai.listEach('.photo_ss',function(obj){
	obj.onclick = function(){
		var uid = parseInt(obj.getAttribute("uid"));
		var title2 = obj.getAttribute("title2");
		var photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url"));
		crm_homepage({uid:uid,title2:title2,photo_s_url:photo_s_url});
	}
});
zeai.listEach('.hnadd',function(obj){
	obj.onclick = function(){
		var uid = parseInt(obj.getAttribute("uid")),
		title2 = obj.getAttribute("title2"),
		photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url")),
		photo_s_iframe = '<img src="'+photo_s_url+'" class="photo_s_iframe">';
		zeai.iframe(photo_s_iframe+'【'+decodeURIComponent(title2)+'】分配售前红娘','crm_hn_utask_add.php?t=1&ulist='+uid,400,500);
	}
});
zeai.listEach('.hnmod',function(obj){
	obj.onclick = function(){
		var uid = parseInt(obj.getAttribute("uid")),
		title2 = obj.getAttribute("title2"),
		photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url")),
		photo_s_iframe = '<img src="'+photo_s_url+'" class="photo_s_iframe">';
		zeai.iframe(photo_s_iframe+'【'+decodeURIComponent(title2)+'】更换售前红娘','crm_hn_utask_add.php?t=2&ulist='+uid,400,500);
	}
});
zeai.listEach('.gjlist',function(obj){
	obj.onclick = function(){
		var uid = parseInt(obj.getAttribute("uid")),
		title2 = obj.getAttribute("title2"),
		photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url")),
		urlpre = 'crm_gj_yj.php?uid='+uid+'&submitok=',
		photo_s_iframe = '<img src="'+photo_s_url+'" class="photo_s_iframe">';
		zeai.iframe(photo_s_iframe+'【'+decodeURIComponent(title2)+'】跟进管理'+
		'<div class="iframeAbox modedatabox" id="modedatabox">'+
		'<a onclick="iframe_A(\'modedatabox\',\''+urlpre+'gj_list\',this);" class="ed"><i class="ico add">&#xe64c;</i> 跟进列表</a>'+
		'<a onclick="iframe_A(\'modedatabox\',\''+urlpre+'gj_add\',this);"><i class="ico add">&#xe622;</i> 新增跟进</a>'+
		'</div>',urlpre+'gj_list',700,520);
	}
});
</script>
<?php }?>
<?php require_once 'bottomadm.php';?>

